package com.arch.hdfs;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FileStatus;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path;

import java.io.IOException;

/**
 * @author pizhihui
 * @date 2024-06-19 13:46
 */
public class GlobblerDemo {


    public static void main(String[] args) throws IOException {

        System.setProperty("HADOOP_USER_NAME", "biadmin");


        Configuration conf = new Configuration();
        conf.addResource("core-site.xml");
        conf.addResource("hdfs-site.xml");

        String pattern = "/tmp/data";


        Path globPath = new Path(pattern);
        FileSystem fs = globPath.getFileSystem(conf);


        FileStatus[] fileStatuses = fs.globStatus(new Path(pattern));

        for (FileStatus fileStatus : fileStatuses) {

            Path path = fileStatus.getPath();

            System.out.println("cur: " + path);

            // namenode.getListing(src, startAfter, needLocation);
            FileStatus[] childFs = fs.listStatus(path);
            for (FileStatus childF : childFs) {
                System.out.println("child: " + childF);
            }

        }


    }

}
